
import unittest
import itertools

class TriangleCounter:
    
    def __init__(self,points,lines):
        self.lines = lines
        self.points = points
    
    def isTriangle(self,(a,b,c)):
        if self.connected(a,b) and \
           self.connected(b,c) and \
           self.connected(a,c) and \
           self.not_on_a_line(a,b,c):
            return True
        else:
            return False
    
    def connected(self,a,b):
        for line in self.lines:
            if set([a,b]) <= set(line):
                return True
        return False
    
    def not_on_a_line(self,a,b,c):
        for line in self.lines:
            if set([a,b,c]) <= set(line):
                return False
        return True
    
    def count(self):
        triangles = list(itertools.combinations(points, 3))
        i = 0
        for tri in triangles:
            if self.isTriangle(tri):
                i += 1
                print "".join(tri)
        print i

        

# class MyTest(unittest.TestCase):
#     def test_point_in_a_line(self):
#         lines=["ab","adc","aef","bde","bcf"]
#         counter = TriangleCounter(lines)
#         self.assertTrue(counter.isTriangle(('a','b','c')))
#         self.assertFalse(counter.isTriangle(('a','d','c')))
#         
#     def test_triangle(self):
#         lines = [Line("ab"),Line("bc"),Line("ac")]
#         points = ['a', 'b', 'c']
#         self.assertTrue(isTriAngle(lines, points, "abc"))
        
points ="abcdef"
lines=["ab","adc","aef","bde","bcf"]

counter = TriangleCounter(points, lines)
counter.count()

points ="abcdefghij"
lines=["ab","acg","adh","aei","afj","bcdef","bghij"]
counter = TriangleCounter(points, lines)
counter.count()


